load("//bazel:mongo_src_rules.bzl", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_test", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob(["*.h"]) + glob(["*.cpp"]),
)

mongo_cc_library(
    name = "visibility_test_libcommon",
    srcs = [
        "visibility_test_libcommon.cpp",
    ],
    hdrs = [
        "visibility.h",
        "visibility_test_libcommon.h",
    ],
    mongo_api_name = "visibility_test_libcommon",
)

mongo_cc_library(
    name = "visibility_test_lib1",
    srcs = [
        "visibility_test_lib1.cpp",
    ],
    hdrs = [
        "visibility_test_lib1.h",
    ],
    mongo_api_name = "visibility_test_lib1",
    deps = [
        ":visibility_test_libcommon",
    ],
)

mongo_cc_library(
    name = "visibility_test_lib2",
    srcs = [
        "visibility_test_lib2.cpp",
    ],
    hdrs = [
        "visibility_test_lib2.h",
    ],
    mongo_api_name = "visibility_test_lib2",
    deps = [
        ":visibility_test_lib1",
    ],
)

# Run it as an executable:
#   bazel run //src/mongo/platform:visibility_test1
#
# Execute as a test (this will parallelize the runs and accept test-specific options):
#   bazel test //src/mongo/platform:visibility_test1 --test_output=all
#
# Test and collect code coverage (notice the "_with_debug" suffix):
#   bazel coverage //src/mongo/platform:visibility_test1_with_debug --test_output=all --config=local --combined_report=lcov
#
# View coverage reports locally
#   genhtml --branch-coverage --output coverage "$(bazel info output_path)/_coverage/_coverage_report.dat"
# That creates a file-tree inside a top-level “coverage” folder. To view the rendered HTML report
# in VSCode, install the [Live HTML Previewer](https://marketplace.visualstudio.com/items?itemName=hdg.live-html-previewer)
# VSCode extension. Once installed, open the coverage/index.html file and click the “Show Preview”
# widget that comes from the extension.
mongo_cc_unit_test(
    name = "visibility1_test",
    srcs = [
        "visibility_test1.cpp",
        "//src/mongo/util:exit_code.h",
    ],
    has_custom_mainline = True,
    tags = [
        "mongo_unittest_second_group",
        "server-programmability",
    ],
    deps = [
        ":visibility_test_lib1",
    ],
)

mongo_cc_unit_test(
    name = "visibility2_test",
    srcs = [
        "visibility_test2.cpp",
        "//src/mongo/util:exit_code.h",
    ],
    has_custom_mainline = True,
    tags = [
        "mongo_unittest_first_group",
        "server-programmability",
    ],
    deps = [
        ":visibility_test_lib2",
    ],
)

mongo_cc_unit_test(
    name = "platform_test",
    srcs = [
        "atomic_proxy_test.cpp",
        "atomic_test.cpp",
        "bits_test.cpp",
        "decimal128_bson_test.cpp",
        "decimal128_test.cpp",
        "endian_test.cpp",
        "int128_test.cpp",
        "overflow_arithmetic_test.cpp",
        "process_id_test.cpp",
        "random_test.cpp",
        "source_location_test.cpp",
        "source_location_test.h",
        "stack_locator_test.cpp",
        "waitable_atomic_test.cpp",
        "//src/mongo/unittest:join_thread.h",
    ],
    tags = [
        "mongo_unittest_second_group",
        "server-programmability",
    ],
)

mongo_cc_unit_test(
    name = "rwmutex_test",
    srcs = [
        "rwmutex_test.cpp",
        "//src/mongo/unittest:join_thread.h",
    ],
    tags = [
        "mongo_unittest_third_group",
        "server-programmability",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_benchmark(
    name = "endian_bm",
    srcs = [
        "endian_bm.cpp",
    ],
    tags = ["first_half_bm"],
    deps = [],
)

mongo_cc_benchmark(
    name = "rwmutex_bm",
    srcs = [
        "rwmutex_bm.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/util:processinfo",
    ],
)
